package com.vodone.v1pin.active.delegate
{
	import com.vodone.v1pin.active.vo.ActiveChildVO;
	import com.vodone.v1pin.active.vo.ActiveVO;
	
	import mx.collections.ArrayCollection;

	public class ActiveUtil
	{
		public static function getActiveListFromObj(obj:Object):ArrayCollection
		{
			var list:ArrayCollection = new ArrayCollection();
			if(obj && obj is Array)
			{
				var arr:Array = obj as Array;
				if(arr && arr.length > 0)
				{
					for(var i:int = 0; i< arr.length ; i++)
					{
						list.addItem(getActiveItem(arr[i]));
					}
				}
			}
			return list;
		}
		public static function getActiveItem(obj:Object):ActiveVO
		{
			var item:ActiveVO = new ActiveVO();
			if(obj)
			{
				if(obj.hasOwnProperty("id"))
				{
					item.id = obj["id"];
				}
				if(obj.hasOwnProperty("aName"))
				{
					item.aName = obj["aName"];
				}
				if(obj.hasOwnProperty("aType"))
				{
					item.aType = obj["aType"];
				}
				if(obj.hasOwnProperty("width"))
				{
					item.imgWidth = obj["width"];
					if( item.imgWidth == 0 ){
						item.imgWidth = 960;
					}
				}
				if(obj.hasOwnProperty("height"))
				{
					item.imgHeight = obj["height"];
					if( item.imgHeight == 0 ){
						item.imgHeight = 500;
					}
				}
				if(obj.hasOwnProperty("url"))
				{
					item.url = obj["url"];
//					item.url = "http://v1admin.suizui.net/Swf/img2012713113052828.jpg";
				}
				if(obj.hasOwnProperty("navUrl"))
				{
					item.navUrl = obj["navUrl"];
				}
				if(obj.hasOwnProperty("samllPic"))
				{
					item.childList = getActiveChildList(obj["samllPic"]);
				}
			}
			return item;
		}
		public static function getActiveChildList(obj:Object):Array
		{
			var list:Array = [];
			if(obj && obj is Array)
			{
				var arr:Array = obj as Array;
				if(arr && arr.length > 0)
				{
					for(var i:int = 0 ;i < arr.length ; i++)
					{
						list.push( getActiveChildItem(arr[i]) );
					}
				}
				
			}
			return list;
		}
		public static function getActiveChildItem(obj:Object):ActiveChildVO
		{
			var item:ActiveChildVO = new ActiveChildVO();
			if(obj)
			{
				if(obj.hasOwnProperty("id"))
				{
					item.id = obj["id"];
				}
				if(obj.hasOwnProperty("url"))
				{
					item.url = obj["url"];
				}
				if(obj.hasOwnProperty("name"))
				{
					item.name = obj["name"];
				}
				if(obj.hasOwnProperty("navURL"))
				{
					item.navURL = obj["navURL"];
				}
				if(obj.hasOwnProperty("x"))
				{
					item.x = obj["x"];
				}
				if(obj.hasOwnProperty("y"))
				{
					item.y = obj["y"];
				}
				if(obj.hasOwnProperty("height"))
				{
					item.height = obj["height"];
				}
				if(obj.hasOwnProperty("width"))
				{
					item.width = obj["width"];
				}
			}
			return item;
		}
	}
}